﻿@page "/So/SaleReturnDetail/BatchEdit"
@using nERP.ViewModel.So.SaleReturnDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <div style="margin-bottom:10px;"> @WtmBlazor.Localizer["Sys.BatchEditConfirm"]</div>
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
        <BootstrapInput @bind-Value="@Model.LinkedVM.Seq" />
        <Select @bind-Value="@Model.LinkedVM.SaleReturnId" Items="AllSaleReturns" Id="g9f81ff0652b14e918df335766f41c285" />
        <Select @bind-Value="@Model.LinkedVM.SaleOutWarehouseDetailId" Items="AllSaleOutWarehouseDetails" Id="g1661585d7bd44144854f9214bc234f62" />
        <Select @bind-Value="@Model.LinkedVM.SaleId" Items="AllSales" Id="g0a342c68826549aba57fddbce7588ffe" />
        <Select @bind-Value="@Model.LinkedVM.SaleDetailId" Items="AllSaleDetails" Id="g95702d1fad5c4e6d863edf4a22edbb81" />
        <Select @bind-Value="@Model.LinkedVM.GoodsId" Items="AllGoodss" Id="ge957b05d55b64b8da6fe27475ae1b1a4" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsName" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsSpec" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.GoodsUnit" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.ReturnNumber" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.UnitPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TotalPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.DiscountPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TaxRate" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TaxUnitPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TaxPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.TotalTaxPrice" />
        <BootstrapInput @bind-Value="@Model.LinkedVM.Remark" />
    </Row>

    <div class="modal-footer table-modal-footer">
        <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
        <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
    </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private SaleReturnDetailBatchVM Model = new SaleReturnDetailBatchVM();
    private ValidateForm vform { get; set; }

    private async Task Submit(EditContext context)
    {
        Model.Ids = ids;
        await PostsForm(vform, "/api/So/SaleReturnDetail/BatchEdit", (s) => WtmBlazor.Localizer["Sys.BatchEditSuccess", s], method: HttpMethodEnum.POST);
    }


    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllSaleReturns = new List<SelectedItem>();
    private List<SelectedItem> AllSaleOutWarehouseDetails = new List<SelectedItem>();
    private List<SelectedItem> AllSales = new List<SelectedItem>();
    private List<SelectedItem> AllSaleDetails = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSaleReturns = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleReturns");
        AllSaleReturns.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleOutWarehouseDetails = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleOutWarehouseDetails");
        AllSaleOutWarehouseDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSales = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSales");
        AllSales.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleDetails = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleDetails");
        AllSaleDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });

        await base.OnInitializedAsync();
    }
}
